<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-detect-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">名称：</label>
            <div class="col-sm-8">
                <input id="name" name="name" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="onoffswitch">
                    <input type="checkbox" th:checked="true" class="onoffswitch-checkbox" id="state" name="state">
                    <label class="onoffswitch-label" for="state">
                        <span class="onoffswitch-inner"></span>
                        <span class="onoffswitch-switch"></span>
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">折扣：</label>
            <div class="col-sm-8">
                <input id="discount" name="discount" class="form-control" type="text" required>
            </div>
        </div>

    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "system/detect"
    $("#form-detect-add").validate({
        rules: {
            name: {
                required: true
            },
            discount: {
                required: true,
                range: [0, 1]
            },
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }
    function add() {
        var name = $("input[name='name']").val();
        var discount = $("input[name='discount']").val();
        var state = $("input[name='state']").is(':checked') == true ? 0 : 1;
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "system/detect/add",
            data : {
                "name": name,
                "discount": discount,
                "state": state
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }
</script>
</body>
</html>
